package com.rupeng.service;

import java.util.List;

import com.rupeng.annotation.RupengCacheable;
import com.rupeng.annotation.RupengUseCache;
import org.springframework.stereotype.Service;

import com.rupeng.pojo.Segment;
import com.rupeng.pojo.User;
import com.rupeng.pojo.UserSegment;
import com.rupeng.util.CommonUtils;

@Service
@RupengCacheable
public class UserSegmentService extends ManyToManyBaseService<UserSegment, User, Segment> {

	@RupengUseCache
	public Long selectLatestSegmentId(Long userId) {
		UserSegment userSegment = new UserSegment();
		userSegment.setUserId(userId);
		List<UserSegment> userSegments = super.selectList(userSegment, "createTime desc");
		if (CommonUtils.isEmpty(userSegments)) {
			return null;
		}
		return userSegments.get(0).getSegmentId();
	}

}